<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <title>网站配置</title>
    <meta charset="utf-8" />
    <meta name="keywords" content="" />
    <meta name="description" content="" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <link rel="stylesheet" href="/css/mdui.min.css"/>
    <link rel="stylesheet" href="/css/style.css"/>
    <link rel="stylesheet" href="/css/mdclub.css"/>
</head>

<div th:include="common/adheader::header"></div>
<div class="mdui-tab mdui-shadow-1">
    <a class="mdui-ripple">网站信息</a>
</div>

<!-- 网站信息部分 -->
<div id="websetting" class="mdui-p-a-2">
    <div class="mdui-card mdui-card-shadow option mdui-p-x-2">
        <div class="mdui-textfield">
            <label class="mdui-textfield-label">网站标题</label>
            <input class="mdui-textfield-input" type="text" name="title" v-model="setting.title" required/>
        </div>
        <div class="mdui-textfield">
            <label class="mdui-textfield-label">网站副标题</label>
            <input class="mdui-textfield-input" type="text" name="subtitle" v-model="setting.subtitle" required/>
        </div>
        <div class="mdui-textfield">
            <label class="mdui-textfield-label">网站简介</label>
            <textarea class="mdui-textfield-input" rows="5" type="text" name="desc" maxlength="100" v-model="setting.desc" required></textarea>
        </div>
        <div class="mdui-textfield">
            <label class="mdui-textfield-label">网站关键词</label>
            <input class="mdui-textfield-input" type="text" name="keywords" v-model="setting.keywords" required/>
        </div>
        <div class="mdui-textfield">
            <label class="mdui-textfield-label">网站地址</label>
            <input class="mdui-textfield-input" type="text" name="domain" v-model="setting.domain" required/>
        </div>
        <div class="mdui-textfield">
            <label class="mdui-textfield-label">网站备案信息</label>
            <textarea class="mdui-textfield-input" type="text" name="icp" rows="3" v-model="setting.icp" required/></textarea>
        </div>
        <button class="mdui-btn mdui-color-theme-accent mdui-btn-raised mdui-m-b-2" @click="update">保存</button>
    </div>
</div>
<div th:include="common/adfooter::footer"></div>
<script>
    let websetting = new Vue({
        el: '#websetting',
        data: {
            setting: [],
        },
        methods: {
            update: function() {
                fetch('/api/upwebinfo', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    body: JSON.stringify({
                        title:this.setting.title,
                        subtitle : this.setting.subtitle,
                        desc:this.setting.desc,
                        keywords:this.setting.keywords,
                        domain:this.setting.domain,
                        icp:this.setting.icp
                    }),

                })
                    .then(response => response.json())
                    .then(json => {
                        if (json.code===20000){
                            mdui.snackbar(json.data);
                        }else {
                            mdui.snackbar(json.msg);
                        }

                    });
            },
        },
        created() {
            fetch('/api/webinfo')
                .then(response => response.json())
                .then(json => {
                    this.setting = json.data;
                    this.setting.close_site = Boolean(parseInt(this.setting.close_site));
                    this.setting.cc_protect = Boolean(parseInt(this.setting.cc_protect));
                    this.setting.fire_wall = Boolean(parseInt(this.setting.fire_wall));
                });
        }
    });

</script>